
// jms: Maybe we can remove this?
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "swagme.h"
#include "Player.h"
#include "Scene.h"
#include "Display.h"
#include "Game.h"

// modified from http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/tut1

int main(int argc, char *argv[])
{
  printf("In dir (%s)\n", argv[0]);

  cout <<"Initializing SDL." << endl;
  if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
    printf("Unable to init SDL: %s\n", SDL_GetError());
    exit(1);
  } else {
    cout << "Initialized SDL correctly" << endl;
  }
  atexit(SDL_Quit);

  SDL_WM_SetCaption("Swag Me", "Swag Me");

  // initialize the game and the Display (my plan is to eventually move Scene,
  // Player, Sprite instances into the Game and Display objects)
  Game theGame;

  int done=0;
  while(done == 0)
  {
    // handle events
    Uint8 *keystate;
    SDL_Event event;
    while ( SDL_PollEvent(&event) )
    {
      switch (event.type) {
        case SDL_QUIT:
          done = 1;
          break;
        case SDL_KEYDOWN:
          switch (event.key.keysym.sym) {
            case SDLK_ESCAPE: // fallthrough
            case SDLK_RETURN:
              done = 1;
              break;
            default:
              break;
          }
          break;
        default:
          break;
      }
    }
    keystate = SDL_GetKeyState(NULL);

    // update Game and Status area (eventually my plan is to migrate 
    // more stuff into this and the Display objects)
    theGame.Update(keystate);
  } // while(done == 0)

  return 0;
}
